﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.Net.Http;
using System.IO;
using System.Web.Http;
using ExpenseSystem.Core;
using ExpenseSystem.Core.Authority;
using ExpenseSystem.Core.Converter;
using ExpenseSystem.Core.BaseModules;
using ExpenseSystem.Fether;
using ExpenseSystem.Common;
using ExpenseSystem.Lor;
using ExpenseSystem.Model;
using ExpenseSystem.Common.BaseModel;

namespace ExpenseSystem.Controllers
{
    [RoutePrefix("api/CodeGenerator")]
    public class CodeGeneratorController : ApiController
    {
        [Route("Gen")]
        [HttpGet]
        public ResponseModel Gen(string code)
        {
            ResponseModel responseModel = new ResponseModel();
            string message = "";
            CodeGeneratorManager codeGeneratorManager = new CodeGeneratorManager();
            UserProfile userProfile = Authority.GetUserProfile();
            if (userProfile == null)
            {
                responseModel.Result = Definition.RESP_NOT_AUTH;
                responseModel.Count = 0;
                responseModel.Data = null;
                responseModel.Message = "没有授予对应的权限";
                return responseModel;
            }
            long siteid = userProfile.SiteId;
            string result = codeGeneratorManager.GetSeqWithUpdate(siteid, code, out message);
            responseModel.Result = result==""?1:0;
            responseModel.Message = message;
            responseModel.Data = result;
            return responseModel;
        }
    }
}
